package com.oe.ldmrabbitmq.dao;

import com.oe.ldmrabbitmq.enums.EnumOrderStatus;
import com.oe.ldmrabbitmq.pojo.OrderPojo;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Component
public class OrderDao {

    /**
     * 模拟数据库订单表
     */
    Map<String, OrderPojo> order_table=new HashMap<>();

    public String insert(OrderPojo pojo){
        String uuid= UUID.randomUUID().toString();
        pojo.setOrderId(uuid);
        order_table.put(uuid,pojo);
        return uuid;
    }


    public OrderPojo queryOrderById(String orderId){
        return order_table.get(orderId);
    }

    public int updateStatusById(String orderId, EnumOrderStatus status){
        OrderPojo orderPojo = order_table.get(orderId);
        if (orderPojo!=null){
            orderPojo.setStatus(status);
            return 1;
        }
        return 0;
    }
}
